package com.ysy.tz.core.engine;

import java.lang.ref.WeakReference;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class SingletonFactory {
    private static Map<Class, WeakReference<Object>> weakReferenceInstaces = new ConcurrentHashMap();

    public SingletonFactory() {
    }

    public static <E> E getWeakInstace(Class<E> className) {
        WeakReference<Object> reference = (WeakReference)weakReferenceInstaces.get(className);
        Object instace = reference == null ? null : reference.get();
        if (instace == null) {
            Class var3 = SingletonFactory.class;
            synchronized(SingletonFactory.class) {
                reference = (WeakReference)weakReferenceInstaces.get(className);
                instace = reference == null ? null : reference.get();
                if (instace == null) {
                    try {
                        instace = className.getDeclaredConstructor().newInstance();
                    } catch (InstantiationException var6) {
                        var6.printStackTrace();
                    } catch (IllegalAccessException var7) {
                        var7.printStackTrace();
                    } catch (NoSuchMethodException var8) {
                        var8.printStackTrace();
                    } catch (InvocationTargetException var9) {
                        var9.printStackTrace();
                    }

                    weakReferenceInstaces.put(className, new WeakReference(instace));
                }
            }
        }

        return (E)instace;
    }
}
